﻿using Heima.OA.Common;
using Heima.OA.IBLL;
using Heima.OA.Model;
using Heima.OA.UI.Portal.Controllers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Heima.OA.UI.Portal.Areas.Check.Controllers
{
    public class CompensateInventoryController : BaseController
    {
        public IZS_CompensateInventoryService ZS_CompensateInventoryService { get; set; }
        // GET: Check/CompensateInventory
        public string Index(PaginationQuery paginationQuery)
        {
            int total = 0;
            var houseList = ZS_CompensateInventoryService.GetPageEntities(paginationQuery.pagesize, paginationQuery.pageindex, out total, u => u.DelFlag == delflagNormal,
                s => s.CreateTime, true);

            PaginationData data = new PaginationData() { total = total, rows = JsonHandler.ToJson(houseList) };
            JsonMessage msg = JsonHandler.CreateMessage((int)MsgTypeEnum.成功, "", JsonHandler.ToJson(data));

            return JsonHandler.ToJson(msg);
        }

        #region 添加
        public string Create(ZS_CompensateInventory inventory)
        {
            inventory.DelFlag = delflagNormal;
            inventory.CreateTime = DateTime.Now;
            inventory.CreateOperator = LoginUser.UName;

            ZS_CompensateInventoryService.Add(inventory);
            JsonMessage message = JsonHandler.CreateMessage((int)MsgTypeEnum.成功, "添加成功!");
            return JsonHandler.ToJson(message);
        }

        #endregion
        #region 编辑
        public string Edit(ZS_CompensateInventory inventory)
        {
            ZS_CompensateInventory editInventory = ZS_CompensateInventoryService.GetModel(inventory.Id);
            string res = string.Empty;
            if (editInventory == null)
            {
                res = JsonHandler.ToJson(JsonHandler.CreateMessage((int)MsgTypeEnum.错误, "编辑错误!"));
            }
            else
            {
                editInventory.CheckIds = inventory.CheckIds;
                editInventory.MemberIds = inventory.MemberIds;
                editInventory.MemberNames = inventory.MemberNames;
                editInventory.House = inventory.House;
                editInventory.Land = inventory.Land;
                editInventory.TempBuilding = inventory.TempBuilding;
                editInventory.YoungCrops = inventory.YoungCrops;
                editInventory.RemovalFee = inventory.RemovalFee;
                editInventory.TempPlaceFee = inventory.TempPlaceFee;
                editInventory.PrivateUseFee = inventory.PrivateUseFee;
                editInventory.StopProductionFee = inventory.StopProductionFee;
                editInventory.OtherAllowance = inventory.OtherAllowance;

                bool success = ZS_CompensateInventoryService.Update(editInventory);
                if (success)
                {
                    res = JsonHandler.ToJson(JsonHandler.CreateMessage((int)MsgTypeEnum.成功, "编辑成功!"));
                }
            }

            return res;
        }
        #endregion
        #region 删除
        public string Delete(int id)
        {
            ZS_CompensateInventory inventory = ZS_CompensateInventoryService.GetModel(id);
            string res = string.Empty;
            if (inventory == null)
            {
                res = JsonHandler.ToJson(JsonHandler.CreateMessage((int)MsgTypeEnum.错误, "删除错误!"));
            }
            else
            {
                inventory.DelFlag = (int)DelFlagEnum.Deleted;
                bool success = ZS_CompensateInventoryService.Update(inventory);
                if (success)
                {
                    res = JsonHandler.ToJson(JsonHandler.CreateMessage((int)MsgTypeEnum.成功, "删除成功!"));
                }
            }
            return res;
        }
        #endregion


    }
}